package com.kob.backend.service.impl.shop;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kob.backend.mapper.ShopMapper;
import com.kob.backend.pojo.shop;
import com.kob.backend.service.shop.ShopRegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class ShopRegisterServiceImpl implements ShopRegisterService {
    @Autowired
    private ShopMapper shopMapper;
    @Override
    public Map<String, String> shopregister(String shopname, String shopaddress, String shopphone) {
        Map<String,String>map=new HashMap<>();
        if(shopname==""||shopname==null)
        {
            map.put("error_message","名字不能为空");
            return map;
        };
        if(shopaddress==""||shopaddress==null)
        {
            map.put("error_message","地址不能为空");
            return map;
        };
        if(shopphone==""||shopphone==null)
        {
            map.put("error_message","电话号码不能为空");
            return map;
        };
        QueryWrapper queryWrapper =new QueryWrapper<shop>();
        queryWrapper.eq("shopname",shopname);
        List<shop> shops=shopMapper.selectList(queryWrapper);
        if(!shops.isEmpty())
        {
            map.put("error_message","店铺名已被使用");
            return map;
        }
        shop new_shop = new shop(null,shopname,shopaddress,shopphone);
        shopMapper.insert(new_shop);
        map.put("error_message","success");
        return map;
    }
}
